import profile
from registration.backends.default import DefaultBackend


class RegBackend(DefaultBackend):

    def user_created(sender, user, request, **kwargs):
        form = profile.UserRegistrationForm(request.POST)
        
        data = profile.Profile(user=user)		
        data.address = form.data["address"]
        data.city = form.data["city"]
        data.county1 = form.data["volunteer_county1"]
        data.county2 = form.data["volunteer_county2"]
        data.county3 = form.data["volunteer_county3"]
        data.email = form.data["email"]
        data.age = form.data["agerange"]
        data.phone = form.data["phone"]
        data.ecfirst_name = form.data["emergency_contact_first_name"]
        data.eclast_name = form.data["emergency_contact_last_name"]
        data.ecphone = form.data["emergency_contact_phone"]
        data.ecrelationship = form.data["emergency_contact_relationship"]
        
        data.save()
        
        user.first_name = form.data["first_name"]
        user.last_name = form.data["last_name"]
        user.save()

    from registration.signals import user_registered
    user_registered.connect(user_created)
